package utils

import config.MyFile
import org.apache.commons.io.FileUtils

import scala.io.Source
import scala.jdk.CollectionConverters._

object getCdsAndPep extends MyFile {

  def main(args: Array[String]): Unit = {
    "D:\\红掌数据库\\pep".listFile.foreach { x =>
      val buffer = x.readLines
      FileUtils.writeLines("D:\\红掌数据库/pep.fa".toFile, buffer.asJava, true)
    }
  }

  def getGenome = {
    "D:\\红掌数据库\\fasta".listFile.foreach { x =>
      val name = x.getName.split('.').head.trim
      Source.fromFile(x).getLines().foreach { y =>
        val line = if (y.startsWith(">")) {
          y.split(" ").head.trim + "-" + name
        } else {
          y
        }
        FileUtils.writeStringToFile("D:\\红掌数据库/genome.fa".toFile, line.trim + "\n", true)
      }
    }
  }

  def getFa = {
    "D:\\红掌数据库\\pep".listFile.foreach { x =>
      val str = x.readFileToString.split(">").tail.map { y =>
        val line = y.split("\n")
        ">" + line.head.split('.').head + "\n" + line.tail.mkString
      }.mkString("\n")

      FileUtils.writeStringToFile(s"D:\\红掌数据库\\${x.getName}".toFile, str)

    }
  }
}
